package edu.sias.hyzn.controller;

import edu.sias.common.core.controller.BaseController;
import edu.sias.common.core.domain.AjaxResult;
import edu.sias.common.core.page.TableDataInfo;
import edu.sias.hyzn.service.impl.EyeAnalysisResultService;
import edu.sias.hyzn.vo.DiseaseStatQuery;
import edu.sias.hyzn.vo.DiseaseStatsVO;
import edu.sias.hyzn.vo.EyeAnalysisResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/hyzn/eye-analysis")
public class EyeAnalysisController extends BaseController {

    private final EyeAnalysisResultService eyeAnalysisResultService;

    @Autowired
    public EyeAnalysisController(EyeAnalysisResultService eyeAnalysisResultService) {
        this.eyeAnalysisResultService = eyeAnalysisResultService;
    }

    @GetMapping("/list")
    public TableDataInfo list(EyeAnalysisResult eyeAnalysisResult){
        startPage();
        List<EyeAnalysisResult> list = eyeAnalysisResultService.selectEyeAnalysisResultList(eyeAnalysisResult);
        return getDataTable(list);
    }

    @GetMapping("/disease-stats")
    public AjaxResult getStats(@Valid DiseaseStatQuery query) {
        List<DiseaseStatsVO> result = eyeAnalysisResultService.getDiseaseStatsByGroup(query.getGroupBy());
        return AjaxResult.success(result);
    }
}
